import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { WindowEvent } from "../../../../component/window/WindowEvent";
import { AIManager } from "../../../scene/ai/AIManager";
import { Cache } from "../../../cache/Cache";
import { ENpcEffect } from "../../../../../Message/Public/ENpcEffect";
import { AIType } from "../../../scene/ai/AIType";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { ObjCreate } from "../../common/ObjCreate";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { SecTimerView } from "../../common/SecTimerView";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ClockManager } from "../../../manager/ClockManager";
import { EGuildwarState } from "../../guildWar/defin/EGuildwarState";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ObjTeamCreate } from "../../common/ObjTeamCreate";
import { BgItem } from "../../common/BgItem";
import { MsgManager } from "../../../manager/MsgManager";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GuildwarEnterWindow } from "../../guildWar/GuildwarEnterWindow";
type int = number;
//class KingChampionShipEnterWin
    
    export  class KingChampionShipEnterWin extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._bmpRank1 = new Object /* flash.display.Bitmap */();
            this._bmpRank2 = new Object /* flash.display.Bitmap */();
            this._bmpRank3 = new Object /* flash.display.Bitmap */();
            this._bmpRank456 = new Object /* flash.display.Bitmap */();
            this._bmpKing = new Object /* flash.display.Bitmap */();
            this._bmpLeft = new Object /* flash.display.Bitmap */();
            this._bmpRight = new Object /* flash.display.Bitmap */();
            this._bmpContributeImg = new Object /* flash.display.Bitmap */();
            this._bmpGuildContribute = new Object /* flash.display.Bitmap */();
            setSize(643, 472);
            titleHeight = 26;
            title = Language.getString(80415);
            this.addEventListener(WindowEvent.CLOSE, this.onClose);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAdd);
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            AIManager.onAIControl(Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcGuildDailyGift), AIType.AI_Convey);
            return;
        }

        /* internal  */onClose(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarIsNotice, false));
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this.createBg();
            this.createLeftTopPart();
            this.createLeftBottomPart();
            this.createRightPart();
            LoaderHelp.addResCallBack(ResFileConst.guildWarEnter, this.resGuildWarEnterComplete);
            LoaderHelp.addResCallBack(ResFileConst.exchange, this.resExchangeComplete);
            LoaderHelp.addResCallBack(ResFileConst.kingChampionShip, this.onGetKingRes);
            var loc1=0;
            if (Cache.instance.guild.myGuildInfo) 
            {
                loc1 = Cache.instance.guild.myGuildInfo.contribution;
            }
            this.updateContribution(loc1);
            return;
        }

        /* internal  */createBg(): void
        {
            ObjCreate.createBg(17, 38, 330, 142, this);
            ObjCreate.createBg(17, 184, 330, 277, this);
            ObjCreate.createBg(349, 38, 277, 423, this);
            return;
        }

        /* internal  */createLeftBottomPart(): void
        {
            var loc3=null;
            this._txtDuoCheng = ObjCreate.createGTextField("", 16, 196, 328, 20, this);
            var loc1=this._txtDuoCheng.defaultTextFormat;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._txtDuoCheng.defaultTextFormat = loc1;
            this._txtDuoCheng.htmlText = HTMLUtil.addColor(Language.getString(80401), "#ffff00");
            this._btnEnter = ObjCreate.createGLoadedButton(ResFileConst.RobCitySignUpBtn, 130, 220, 97, 50, this);
            this._tfLeftTime = new SecTimerView();
            this._tfLeftTime.mouseEnabled = false;
            var loc2=GlobalStyle.textFormat6;
            loc2.bold = true;
            this._tfLeftTime.defaultTextFormat = loc2;
            ObjCreate.setObjAttri(this._tfLeftTime, 104, 285, 170, 20, this);
            this._tfLeftTime.setParse(Language.getString(44255));
            this._tfLeftTime.visible = false;
            ObjCreate.createBg(27, 306, 305, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBg(24, 313, 123, 26, this, ImagesConst.SelectedBg);
            loc1 = GlobalStyle.textFormat1;
            loc1.size = 14;
            ObjCreate.createGTextField(Language.getString(80403), 33, 316, 200, 20, this, loc1);
            loc1.color = GlobalStyle.color9Uint;
            ObjCreate.createGTextField(Language.getString(80404), 72, 345, 200, 20, this, loc1);
            loc1.color = GlobalStyle.color8Uint;
            ObjCreate.createGTextField(Language.getString(80405), 72, 388, 200, 20, this, loc1);
            loc1.color = GlobalStyle.color1Uint;
            ObjCreate.createGTextField(Language.getString(80406), 72, 431, 200, 20, this, loc1);
            this._bmpKing.x = 220;
            this._bmpKing.y = 340;
            this.addChild(this._bmpKing);
            this._bmpLeft.x = 198;
            this._bmpLeft.y = 382;
            this.addChild(this._bmpLeft);
            this._bmpRight.x = 198;
            this._bmpRight.y = 424;
            this.addChild(this._bmpRight);
            this._btnEnter.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnEnterClick);
            return;
        }

        /* internal  */createLeftTopPart(): void
        {
            this._spTipContainer = new Object /* flash.display.Sprite */();
            this._spTipContainer.x = 14;
            this._spTipContainer.y = 40;
            this._spTipContainer.mouseEnabled = false;
            this.addChild(this._spTipContainer);
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 11661311);
            loc1.leading = 7;
            loc1.indent = 24;
            this._tfTitle = ObjCreate.createTextField("", 11, 10, 300, 20, this._spTipContainer);
            var loc2=new GTextFormat(FontUtil.songtiName, 12, 64767);
            loc2.align = flash.text.TextFormatAlign.CENTER;
            this._tfTitle.defaultTextFormat = loc2;
            this._tfTitle.text = Language.getString(80402) + ":";
            this._tfContent = ObjCreate.createTextField("", 11, 33, 320, 65, this._spTipContainer, loc1);
            this._tfContent.wordWrap = true;
            this._tfContent.mouseEnabled = false;
            this._tfContent.htmlText = Language.getString(80418);
            this._tfTime = ObjCreate.createTextField("", 40, 100, 320, 20, this._spTipContainer);
            this._tfTime.htmlText = Language.getString(80400);
            return;
        }

        /* internal  */onBtnEnterClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.KingChampionShipEnterCopyReq));
            return;
        }

        public updateEndTime(arg1: Date): void
        {
            this._tfLeftTime.visible = true;
            this._tfLeftTime.setLeftTime(int((arg1.time - ClockManager.instance.nowDate.time) / 1000));
            return;
        }

        public setParseAndLeftTime(arg1: string, arg2: int): void
        {
            if (arg2 <= 1) 
            {
                this._tfLeftTime.visible = false;
                return;
            }
            this._tfLeftTime.visible = true;
            this._tfLeftTime.setParse(arg1);
            this._tfLeftTime.setLeftTime(arg2);
            this._tfLeftTime.timeOutHandler = this.timeOutHandler;
            return;
        }

        /* internal  */timeOutHandler(): void
        {
            this._tfLeftTime.visible = false;
            return;
        }

        public updateGuildWarState(arg1: EGuildwarState): void
        {
            this._state = arg1;
            return;
        }

        /* internal  */createRewardSp(arg1: string, arg2: int, arg3: int): Object /* flash.display.Sprite */
        {
            var loc1;
            (loc1 = new Object /* flash.display.Sprite */()).mouseEnabled = false;
            loc1.mouseChildren = false;
            var loc2=ObjCreate.createTextField("", 0, 0, 75, 20, loc1);
            var loc3=ObjCreate.createTextField("", 75, 0, 120, 20, loc1);
            var loc4=ObjCreate.createTextField("", 193, 0, 120, 20, loc1);
            loc2.htmlText = arg1;
            loc3.htmlText = Language.getStringByParam(41877, arg2.toString());
            loc4.htmlText = Language.getStringByParam(41878, arg3.toString());
            return loc1;
        }

        /* internal  */createRightPart(): void
        {
            var loc2=null;
            var loc6=null;
            this._rightPart = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this._rightPart, 349, 38, -1, -1, this);
            var loc1=GlobalClass.getBitmap(ImagesConst.TileBg);
            ObjCreate.setObjAttri(loc1, 3, 3, -1, -1, this._rightPart);
            ObjCreate.createTextField(Language.getString(80415) + Language.getString(80419), 9, 9, 200, 29, this._rightPart, GlobalStyle.textFormat6);
            loc2 = this.createRewardsSp(this._bmpRank1, 34011049, Language.getString(80416));
            ObjCreate.setObjAttri(loc2, 15, 27, -1, -1, this._rightPart);
            loc2 = this.createRewardsSp(this._bmpRank2, 34011050, Language.getString(80416));
            ObjCreate.setObjAttri(loc2, 15, 87, -1, -1, this._rightPart);
            loc2 = this.createRewardsSp(this._bmpRank3, 34011051, Language.getString(80416));
            ObjCreate.setObjAttri(loc2, 15, 147, -1, -1, this._rightPart);
            loc2 = this.createRewardsSp(this._bmpRank456, 34011052, Language.getString(80416));
            ObjCreate.setObjAttri(loc2, 15, 207, -1, -1, this._rightPart);
            ObjCreate.createBg(10, 272, 255, 2, this._rightPart, "SplitLine");
            var loc3=ObjCreate.createBitmap(ImagesConst.PackItemBg, 13, 278, this._rightPart);
            ObjCreate.setObjAttri(this._bmpContributeImg, 16, 280, -1, -1, this._rightPart);
            ObjCreate.setObjAttri(this._bmpGuildContribute, 57, 276, -1, -1, this._rightPart);
            this._myContribute = ObjCreate.createTextField("", 60, 296, 120, 20, this._rightPart);
            ObjTeamCreate.setTextFieldKeyValue(this._myContribute, Language.getString(41637), "0", "#00FF00", "#f0ea3f");
            this._goToExchange = ObjCreate.createGButton(Language.getString(41883), 168, 275, 110, 20, this._rightPart, "LinkButton");
            this._goToExchange.addEventListener(flash.events.MouseEvent.CLICK, this.onGoToExchangeHandler);
            ObjCreate.createBitmap(ImagesConst.Fire, 13, 310, this._rightPart);
            var loc4;
            (loc4 = ObjCreate.createTextField("", 35, 318, 240, 20, this._rightPart, GlobalStyle.textFormatGreen)).htmlText = Language.getString(41884);
            this._aryBgItem = new Array<any>();
            var loc5=0;
            while (loc5 < 12) 
            {
                (loc6 = new BgItem()).x = 17 + 40 * loc5 % 6;
                loc6.y = 337 + int(loc5 / 6) * 40;
                this._rightPart.addChild(loc6);
                this._aryBgItem.push(loc6);
                ++loc5;
            }
            this.updateItem();
            return;
        }

        /* internal  */resGuildWarEnterComplete(): void
        {
            return;
        }

        /* internal  */resExchangeComplete(): void
        {
            this._bmpContributeImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.contriImg);
            this._bmpGuildContribute.bitmapData = GlobalClass.getBitmapData(ImagesConst.title_gongxian);
            return;
        }

        /* internal  */onGetKingRes(): void
        {
            this._bmpKing.bitmapData = GlobalClass.getBitmapData(ImagesConst.KingChampionShip_right);
            this._bmpLeft.bitmapData = GlobalClass.getBitmapData(ImagesConst.KingChampionShip_left);
            this._bmpRight.bitmapData = GlobalClass.getBitmapData(ImagesConst.KingChampionShip_King);
            this._bmpRank1.bitmapData = GlobalClass.getBitmapData(ImagesConst.KingChampionShip_No1);
            this._bmpRank2.bitmapData = GlobalClass.getBitmapData(ImagesConst.KingChampionShip_No2);
            this._bmpRank3.bitmapData = GlobalClass.getBitmapData(ImagesConst.KingChampionShip_No3);
            this._bmpRank456.bitmapData = GlobalClass.getBitmapData(ImagesConst.KingChampionShip_No456);
            return;
        }

        /* internal  */onGoToExchangeHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (Cache.instance.guild.guildInfo == null) 
            {
                MsgManager.showRollTipsMsg(Language.getString(41802));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildOpenShop));
            return;
        }

        /* internal  */onAdd(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarIsNotice, true));
            return;
        }

        /* internal  */onLookTopHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RankSelectedAssignType, {"oneIdx": 1, "twoIdx": 2}));
            return;
        }

        /* internal  */createRewardsSp(arg1: Object /* flash.display.DisplayObject */, arg2: int, arg3: string, arg4: int=1): Object /* flash.display.Sprite */
        {
            var loc1=new Object /* flash.display.Sprite */();
            arg1.y = 6;
            loc1.addChild(arg1);
            var loc2;
            (loc2 = ObjCreate.createTextField("", 0, 30, 100, 20, loc1)).text = arg3;
            var loc3=new ItemData(arg2);
            var loc4;
            (loc4 = ObjCreate.createTextField("", 100, 30, 90, 20, loc1)).htmlText = ItemsUtil.getItemName(loc3);
            var loc5;
            (loc5 = new BgItem()).setItemCode(arg2, arg4);
            ObjCreate.setObjAttri(loc5, 190, 19, -1, -1, loc1);
            return loc1;
        }

        /* internal  */updateItem(): void
        {
            var loc3=null;
            var loc1=[19012000, 19012001, 19022000, 19022001, 19052000, 19052001, 14031003, 14102300, 14102306, 14105301, 14076201, 13600001];
            var loc2=0;
            while (loc2 < this._aryBgItem.length) 
            {
                loc3 = this._aryBgItem[loc2];
                loc3.setItemCode(int(loc1[loc2]));
                ++loc2;
            }
            return;
        }

        public updateContribution(arg1: int): void
        {
            ObjTeamCreate.setTextFieldKeyValue(this._myContribute, Language.getString(41887), arg1.toString(), "#00FF00", "#f0ea3f");
            return;
        }

        /* internal */ /* var */_spTipContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfTitle: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfContent: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfTime: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnEnter: GLoadedButton;

        /* internal */ /* var */_tfLeftTime: SecTimerView;

        /* internal */ /* var */_state: EGuildwarState;

        /* internal */ /* var */_rightPart: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bmpRank1: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpRank2: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpRank3: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpRank456: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpKing: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpLeft: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpRight: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpContributeImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_myContribute: Object /* flash.text.TextField */;

        /* internal */ /* var */_goToExchange: GButton;

        /* internal */ /* var */_aryBgItem: Array<any>;

        /* internal */ /* var */_tfLookTop: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmpGuildContribute: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_txtDuoCheng: GTextFiled;

        /* internal */ static /* var */_instance: GuildwarEnterWindow;
    }
